home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Generic_Defend.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  7.5 KB  |  254 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. fsm Generic_Defend : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Generic_Defend:
  12. //   Defend a target, staying near it at all times.
  13. //   If it is destroyed, just go on a bloody rampage and attack whoever.
  14.  
  15. //------------------------------------------------------------------
  16.  
  17.  
  18.  
  19. //------------------------------------------------------------------
  20. //     Constants
  21. //------------------------------------------------------------------
  22.  
  23.     const
  24.         #include_ <content\ABLScripts\mwconst.abi>
  25.  
  26. //------------------------------------------------------------------
  27. //     Types
  28. //------------------------------------------------------------------
  29.  
  30.     type
  31.         #include_ <content\ABLScripts\mwtype.abi>
  32.     
  33.  
  34. //------------------------------------------------------------------
  35. //     Variables
  36. //------------------------------------------------------------------
  37.  
  38.     var
  39.         static ObjectID            defendTarget1;        // First target to defend
  40.         static ObjectID            defendTarget2;        // Second target to defend
  41.         static ObjectID            defendTarget3;        // Third target to defend
  42.         static ObjectID            defendTarget4;        // Fourth target to defend
  43.         static ObjectID            defendTarget5;        // Fifth target to defend
  44.  
  45.         static integer            rampageAttackRange;    // What is my attack range when my target is destroyed?
  46.                                                                     
  47.         static integer            piloting;            // Piloting skill
  48.         static integer            gunnery;            // Gunnery skill/chance to hit
  49.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  50.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  51.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  52.                                                     // and other things.  It indicates a general level of combat experience.
  53.         static integer            attackThrottle;        // My attack throttle
  54.  
  55.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  56.         static integer            findTypes;            // What kind of enemies to look for
  57.  
  58.         static integer             attackSound;        // The attack sound I play when I first attack
  59.         static integer             deathSound;            // The sound I play when I die
  60.         
  61.         static integer            mood;                // My default mood.
  62.  
  63.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  64.  
  65. //------------------------------------------------------------------
  66. //     Init: my initialization function
  67. //------------------------------------------------------------------
  68.  
  69. function Init;
  70.     code
  71.         // script-specific variables
  72.         rampageAttackRange = 1200;
  73.  
  74.         // defendTarget*: Specifies the targets to defend, and the order in which
  75.         // to defend them.  Fill in as many as appropriate,
  76.         // Fill "defendTarget1" first, and proceed from there, in order,
  77.         // and fill the rest with NO_UNIT.  You must fill in at least the first
  78.         // defend target; the others are optional.
  79.         defendTarget1    = NO_UNIT;
  80.         defendTarget2    = NO_UNIT;
  81.         defendTarget3    = NO_UNIT;
  82.         defendTarget4    = NO_UNIT;
  83.         defendTarget5    = NO_UNIT;
  84.  
  85.         takeOffDistance    = 150;
  86.  
  87.         // driver settings
  88.         piloting        = 50;
  89.         gunnery            = 30;
  90.         minDelay        = 1.5;
  91.         maxDelay        = 3.0;
  92.         eliteLevel        = 30;
  93.         attackThrottle    = 80;
  94.         isShotRadius    = 120;
  95.         attackSound        = -1; // no sound
  96.         deathSound        = -1; // no sound
  97.         mood            = NEUTRAL_START;
  98.         findTypes        = FT_DEFAULT;
  99.  
  100. endfunction;
  101.  
  102. //------------------------------------------------------------------
  103. //    StartState: my initial state
  104. //------------------------------------------------------------------
  105.  
  106. state StartState;
  107.  
  108.     code
  109.         SetFiringDelay            (ME,minDelay,maxDelay);
  110.         SetIgnoreFriendlyFire    (ME,true);
  111.         SetIsShotRadius            (ME,isShotRadius);
  112.         SetEntropyMood            (ME,mood);
  113.         SetCurMood                (ME,mood);
  114.         SetSkillLevel            (ME,piloting,gunnery,eliteLevel);
  115.         SetAttackThrottle        (ME,attackThrottle);
  116.  
  117.         if (orderTakeOff(takeOffDistance) == true) then
  118.             SetTarget(ME,defendTarget1);
  119.             trans Defend1State;
  120.         endif;
  121.  
  122. endstate;            
  123.  
  124. //------------------------------------------------------------------
  125. //    Defend1State: defend the first target
  126. //------------------------------------------------------------------
  127. state Defend1State;
  128.     code
  129.         if (GetTarget(ME) == NO_UNIT) then
  130.             if (defendTarget2 <> NO_UNIT) then
  131.                 SetTarget(ME,defendTarget2);
  132.                 trans Defend2State;
  133.             else
  134.                 trans RampageState;
  135.             endif;
  136.         endif;
  137.         if (attackSound <> -1) then    
  138.             PlaySoundOnce(attackSound);
  139.         endif;
  140.         OrderAttackTactic(TACTIC_DEFEND,true);
  141.  
  142. endstate;
  143.  
  144. //------------------------------------------------------------------
  145. //    Defend2State: defend the second target (if it exists)
  146. //------------------------------------------------------------------
  147. state Defend2State;
  148.     code
  149.         if (GetTarget(ME) == NO_UNIT) then
  150.             if (defendTarget3 <> NO_UNIT) then
  151.                 SetTarget(ME,defendTarget3);
  152.                 trans Defend3State;
  153.             else
  154.                 trans RampageState;
  155.             endif;
  156.         endif;
  157.         if (attackSound <> -1) then    
  158.             PlaySoundOnce(attackSound);
  159.         endif;
  160.         OrderAttackTactic(TACTIC_DEFEND,true);
  161.  
  162. endstate;
  163.  
  164. //------------------------------------------------------------------
  165. //    Defend3State: defend the third target (if it exists)
  166. //------------------------------------------------------------------
  167. state Defend3State;
  168.     code
  169.         if (GetTarget(ME) == NO_UNIT) then
  170.             if (defendTarget4 <> NO_UNIT) then
  171.                 SetTarget(ME,defendTarget4);
  172.                 trans Defend4State;
  173.             else
  174.                 trans RampageState;
  175.             endif;
  176.         endif;
  177.         if (attackSound <> -1) then    
  178.             PlaySoundOnce(attackSound);
  179.         endif;
  180.         OrderAttackTactic(TACTIC_DEFEND,true);
  181.  
  182. endstate;
  183.  
  184. //------------------------------------------------------------------
  185. //    Defend4State: defend the fourth target (if it exists)
  186. //------------------------------------------------------------------
  187. state Defend4State;
  188.     code
  189.         if (GetTarget(ME) == NO_UNIT) then
  190.             if (defendTarget5 <> NO_UNIT) then
  191.                 SetTarget(ME,defendTarget5);
  192.                 trans Defend5State;
  193.             else
  194.                 trans RampageState;
  195.             endif;
  196.         endif;
  197.         if (attackSound <> -1) then    
  198.             PlaySoundOnce(attackSound);
  199.         endif;
  200.         OrderAttackTactic(TACTIC_DEFEND,true);
  201.  
  202. endstate;
  203.  
  204. //------------------------------------------------------------------
  205. //    Defend5State: defend the fifth target (if it exists)
  206. //------------------------------------------------------------------
  207. state Defend5State;
  208.     code
  209.         if (GetTarget(ME) == NO_UNIT) then
  210.             trans RampageState;
  211.         endif;
  212.         if (attackSound <> -1) then    
  213.             PlaySoundOnce(attackSound);
  214.         endif;
  215.         OrderAttackTactic(TACTIC_DEFEND,true);
  216.  
  217. endstate;
  218.  
  219. //------------------------------------------------------------------
  220. //    RampageState: I will have my revenge, in this life or the next!
  221. //------------------------------------------------------------------
  222.  
  223. state RampageState;
  224.     code
  225.         if (FindEnemy(rampageAttackRange,findTypes)) then
  226.  
  227.             if (attackSound <> -1) then    
  228.                 PlaySoundOnce(attackSound);
  229.             endif;
  230.  
  231.             OrderAttack(TRUE);
  232.  
  233.         endif;
  234.  
  235. endstate;
  236.  
  237. //------------------------------------------------------------------
  238. //    DeadState: OK, I kicked the bucket.
  239. //------------------------------------------------------------------
  240.  
  241. state DeadState;
  242.     code
  243.         if (deathSound <> -1) then    
  244.             PlaySoundOnce(deathSound);
  245.         endif;        
  246.  
  247.         orderDie;
  248.  
  249. endstate;
  250.  
  251.  
  252. endfsm.
  253.  
  254.